package newPan3d.content.scene
{
	import _Pan3D.base.Focus3D;
	import _Pan3D.core.MathCore;
	
	import _me.Scene_data;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DTextureFormat;

	public class SceneMenager
	{
		[Embed(source="../_File/nijia2/dengguang1.jpg")]
		private static var pic:Class;
		[Embed(source="../_File/nijia2/newDengGuang.jpg")]
		private static var newDengGuang:Class;
	
		public static function initData():void
		{
			makeBaseCam3D();
			makeSun3D();
			makelight3D();
			makeGroundLightTexture();
			makeSceneLightTexture();
			makeBaseShadowTexture();
			
		
		}
		private static function makeBaseCam3D():void
		{
			//初始化镜头及，焦点位置
			Scene_data.cam3D.distance=300;
			Scene_data.focus3D.angle_y=-0;
			Scene_data.focus3D.angle_x=-45;
			Scene_data.focus3D.x=500;
			Scene_data.focus3D.y=0;
			Scene_data.focus3D.z=500;
		}
		private static function makeSceneLightTexture():void
		{
			//初始化环境光贴图
			var context3D:Context3D=Scene_data.context3D
			var tempBmp:BitmapData=Bitmap(new pic()).bitmapData;
			//tempBmp=new BitmapData(tempBmp.width,tempBmp.height,true,0x00000000)
			//Scene_data.sceneLightText=context3D.createTexture(tempBmp.width,tempBmp.height, Context3DTextureFormat.BGRA,true);
			//Scene_data.sceneLightText.uploadFromBitmapData(tempBmp);
			

		}
		private static function makeGroundLightTexture():void
		{
			
			//初始化地面环境光贴图
			var context3D:Context3D=Scene_data.context3D
			var tempBmp:BitmapData=Bitmap(new newDengGuang()).bitmapData;
			Scene_data.groundLightText=context3D.createTexture(tempBmp.width,tempBmp.height, Context3DTextureFormat.BGRA,true);
			Scene_data.groundLightText.uploadFromBitmapData(tempBmp);
			
			//下面是定义为百色的基础色;
			//Scene_data.groundLightText=context3D.createTexture(64, 64, Context3DTextureFormat.BGRA, true);
			//Scene_data.groundLightText.uploadFromBitmapData(new BitmapData(64, 64, true, 0x00ffffff));
			
		}
		private static function makeBaseShadowTexture():void
		{
			//设定阴影的面积为1024*1024像素的图片资源
			var context3D:Context3D=Scene_data.context3D
			var shadowBitmapData:BitmapData=new BitmapData(1024,1024,false,0xffffff)
			Scene_data.texShadowMap=context3D.createTexture(shadowBitmapData.width,shadowBitmapData.height, Context3DTextureFormat.BGRA,true);
			Scene_data.texShadowMap.uploadFromBitmapData(shadowBitmapData);		
		}
		public static function makeSun3D():void
		{
			//初始化太阳
			Scene_data.sun3D=Scene_data.cam3D.clone();
			var fous3D:Focus3D=Scene_data.focus3D.cloneFocus3D();
			Scene_data.sun3D.distance=2470
			fous3D.x=500
			fous3D.y=0
			fous3D.z=500
			fous3D.angle_x=-75;
			fous3D.angle_y=75;
			MathCore._catch_cam(Scene_data.sun3D, fous3D);
		}
		public static function makelight3D():void
		{
			//初始化灯光位置
			var fous3D:Focus3D=Scene_data.focus3D.cloneFocus3D();
			fous3D.angle_x=-90;
			fous3D.angle_y=0;
			Scene_data.light3D.distance=1024/2;
			Scene_data.light3D.fovw=1024;
			Scene_data.light3D.fovh=1024;
			MathCore._catch_cam(Scene_data.light3D, fous3D);
			
		}
	}
}